package com.example.hotelsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.hotelsystem.entity.City;
import com.example.hotelsystem.entity.UserRole;
import com.example.hotelsystem.entity.vo.CitySearchVO;
import com.example.hotelsystem.mapper.CityMapper;
import com.example.hotelsystem.page.Pagesize;
import com.example.hotelsystem.service.CityService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.hotelsystem.vo.list.ListVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lee
 * @since 2021-03-07
 */
@Service
public class CityServiceImpl extends ServiceImpl<CityMapper, City> implements CityService {
    @Autowired
    CityService cityService;
    @Autowired
    CityMapper cityMapper;

    @Override
    @Transactional
    public List<ListVO> cityListVO(){
    List<ListVO> list = cityMapper.cityListVO();
    return list;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public IPage<City> CitySearchList(CitySearchVO citySearchVO){
        Page page = new Page(citySearchVO.getCurrentPage(), 20);
        QueryWrapper<City> queryWrapper = new QueryWrapper<>();
        if(citySearchVO.getCityName()!=null){
            queryWrapper.like("city_name",citySearchVO.getCityName());
        }
        queryWrapper.eq("is_delete",0);
        IPage<City> citys=cityService.page(page,queryWrapper);
        return citys;
    }

}
